"""add memories table

Revision ID: add_memories
Revises: initial
Create Date: 2023-11-09 11:00:00.000000

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import JSON

# revision identifiers, used by Alembic.
revision = 'add_memories'
down_revision = 'initial'
branch_labels = None
depends_on = None

def upgrade() -> None:
    op.create_table('memories',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('agent_name', sa.String(), nullable=True),
        sa.Column('run_name', sa.String(), nullable=True),
        sa.Column('memory_type', sa.String(), nullable=True),
        sa.Column('thinking', sa.Text(), nullable=True),
        sa.Column('content', JSON, nullable=True),
        sa.Column('vector_id', sa.String(), nullable=True),
        sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
        sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
        sa.Column('is_active', sa.Boolean(), nullable=True),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_memories_agent_name'), 'memories', ['agent_name'], unique=False)
    op.create_index(op.f('ix_memories_id'), 'memories', ['id'], unique=False)
    op.create_index(op.f('ix_memories_memory_type'), 'memories', ['memory_type'], unique=False)
    op.create_index(op.f('ix_memories_run_name'), 'memories', ['run_name'], unique=False)
    op.create_index(op.f('ix_memories_user_id'), 'memories', ['user_id'], unique=False)
    op.create_index(op.f('ix_memories_vector_id'), 'memories', ['vector_id'], unique=False)

def downgrade() -> None:
    op.drop_index(op.f('ix_memories_vector_id'), table_name='memories')
    op.drop_index(op.f('ix_memories_user_id'), table_name='memories')
    op.drop_index(op.f('ix_memories_run_name'), table_name='memories')
    op.drop_index(op.f('ix_memories_memory_type'), table_name='memories')
    op.drop_index(op.f('ix_memories_id'), table_name='memories')
    op.drop_index(op.f('ix_memories_agent_name'), table_name='memories')
    op.drop_table('memories')
